export const axiosTsTemplate = () => {
  return `
    import axios from 'axios'
    import type{ AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios"


    type Response<T =any> = {
    code: number
    message: string
    data: T
    }

    const instance: AxiosInstance = axios.create({
        headers: {
          'token': ''
        },
        // 请求超时时间
        timeout: 5000,
      })
    export default <T> (config: AxiosRequestConfig) => {
        return new Promise<Response<T>>((resolve, reject) => {
          instance.request<Response<T>>(config).then((response: AxiosResponse<Response<T>>) => {
            if (response.data.code !== 200) {
             // 处理非code相关
            }
            resolve(response.data)
          }).catch((error :any) => {
            // 请求失败的处理
            reject(error)
          })
        })
    }`
}

export const requestTsTemplate = () => {
  return `
    import axios from "./axios"

     const get = <T>(url: string, params: any) => axios<T>({
      method: 'get',
      url: url,
      params: params
     })

    const post = <T>(url: string, params: any) => axios<T>({
      method: 'post',
      url: url,
      data: params
    })
    const request = {
      get,
      post,
    }

export default request
    
    `
}
